<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>退款</title>
</head>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="com.zjitc.config.*"%>
<%@ page import="com.alipay.api.*"%>
<%@ page import="com.alipay.api.request.*"%>
<%@ page import="com.google.gson.Gson" %>
<%@ page import="com.zjitc.pojo.refund.Refund" %>
<%@ page import="com.zjitc.pojo.refund.AlipayRefund" %>
<%
	//获得初始化的AlipayClient
	AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
	
	//设置请求参数
	AlipayTradeRefundRequest alipayRequest = new AlipayTradeRefundRequest();
	
	//商户订单号，商户网站订单系统中唯一订单号
	String oid = request.getParameter("oid");
	//支付宝交易号
//	String tradeNo = request.getParameter("WIDTRtrade_no");
	//请二选一设置
	//需要退款的金额，该金额不能大于订单金额，必填
	String total = request.getParameter("total");
	//退款的原因说明
	String reason = request.getParameter("reason");
	//标识一次退款请求，同一笔交易多次退款需要保证唯一，如需部分退款，则此参数必传
//	String out_request_no = request.getParameter("WIDTRout_request_no");

	alipayRequest.setBizContent("{\"out_trade_no\":\""+ oid +"\","
			+ "\"refund_amount\":\""+ total +"\","
			+ "\"refund_reason\":\""+ reason +"\","
			+ "\"operator_id\":\"OP001\"," +
			"\"store_id\":\"NJ_S_001\"," +
			"\"terminal_id\":\"NJ_T_001\"" +
			"}");
	
	//请求
	String result = alipayClient.execute(alipayRequest).getBody();
	
	//输出
	out.println(result);
	System.out.println("退款到达输出步骤");
	Gson gson = new Gson();
	AlipayRefund alipayrefund = gson.fromJson(result, AlipayRefund.class);
	String msg = alipayrefund.getAlipay_trade_refund_response().getMsg();
//	request.getRequestDispatcher("/order/refund.do?msg="+msg).forward(request,response);
	response.sendRedirect("/shopClient/order/refund.do?msg="+msg +"&oid="+oid);
%>
<body>
</body>
</html>